package 题目集.hash;

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

//https://www.acwing.com/problem/content/2060/
public class 笨拙的手指 {

    /**
     * 秦九韶算法将n进制的num转换为十进制
     * 从高位到低位，每次乘n再加上当前位的数字
     * @param num
     * @param n
     * @return
     */
    public static int parse(char[] num, int n) {
        int res = 0;
        for (int i = 0; i < num.length; i++) {
            res = res * n + num[i] - '0';
        }
        return res;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] a = sc.nextLine().toCharArray();
        char[] b = sc.nextLine().toCharArray();
        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < a.length; i++) {
            if (i == 0 && a.length > 1 && a[i] == '1') continue; //第一位不能转化为0
            a[i] = (char) ('0' + ((a[i] - '0') ^ 1)); //在该位上取反
            set.add(parse(a, 2));
            a[i] = (char) ('0' + ((a[i] - '0') ^ 1)); //在该位上取反
        }
        for (int i = 0; i < b.length; i++) {
            int k = b[i] - '0';
            for (int j = 0; j < 3; j++) {
                if (k != j) {
                    b[i] = (char) ('0' + j);
                    if (i == 0 && b[i] == '0' && a.length > 1) continue; //第一位不能转化为0
                    int parse = parse(b, 3);
                    if (set.contains(parse)) {
                        System.out.println(parse);
                        return;
                    }
                }
            }
            b[i] = (char) ('0' + k);
        }
    }

}
